﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autofac;
using BanZuiCloudControlAgent.Core.Mqtt;
using BanZuiCloudControlAgent.Core.Startup;
using BanZuiCloudControlAgent.UI;
using BanZuiCloudControlAgent.Utils.Common;
using BanZuiCloudControlAgent.Utils.Exceptions;
using BanZuiCloudControlAgent.Utils.Logging;

namespace BanZuiCloudControlAgent
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // 初始化日志系统
                LogManager.Initialize();
                var logger = LogManager.GetLogger("Program");
                logger.Info("应用程序启动");

                // 初始化异常处理
                ExceptionHandler.Initialize();

                // 初始化依赖注入容器
                ContainerConfig.Initialize();
                
                // 初始化启动管理器
                StartupManager.Initialize();

                // 启动主窗体
                Application.Run(new FrmMain());
            }
            catch (Exception ex)
            {
                MessageBox.Show($"应用程序启动失败: {ex.Message}\n\n{ex.StackTrace}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
